package capplauncher.utils;

import java.io.IOException;
import capplauncher.log.Logger;


public class SystemChecker {
	/* constant of the System
	 * require 1.5GB of RAM (java RUNTIME)
	 * require 1.7.0+ JAVA Version 
	 */
	final private int MB = 1024*1024;
    final private double LOWESTRAM = 1.5;
    final private double LOWESTVERSION = 1.7;
    
    private String osName;
    private double javaRam;
    private double javaVersion;
    private Logger log;
	
    public SystemChecker(Logger logger){
    	// init of program
        osName = System.getProperty("os.name");
        javaRam = Runtime.getRuntime().maxMemory()/MB;
        javaVersion = Double.parseDouble(System.getProperty("java.version").substring(0,4));// >=1.7.0
        log = logger;
    }
	
    public void printAll(){
        // this is a debug function which will not be use in the real program
        System.out.println("osName: "+osName);
        System.out.println("javaRam: "+javaRam);
        System.out.println("javaVersion: "+javaVersion);
    }
    
    public boolean checkAbility()throws IOException{
        log.log(1, "javaRam: "+javaRam);
        log.log(1, "javaVersion: "+javaVersion);
    	return javaRam>=LOWESTRAM&&javaVersion>=LOWESTVERSION;
        
    }
    
}
